

export default {
    warning(msg, duration) {
        toastTemplate(msg, duration,'toast toast-warning')
    },
    succeed(msg, duration){
        toastTemplate(msg, duration,'toast toast-succeed')
    },
    error(msg, duration){
        toastTemplate(msg, duration,'toast toast-error')
    },
}

// toast
function toastTemplate(msg, duration, className){
    duration = isNaN(duration) ? 3000 : duration;
    let m = document.createElement('div');
    m.innerHTML = msg;
    m.className = className;
    document.body.appendChild(m);
    setTimeout(function () {
        let d = 0.5;
        m.style.webkitTransition = `-webkit-transform ${d}s ease-in, opacity ${d}s ease-in`;
        m.style.opacity = '0';
        setTimeout(function () { document.body.removeChild(m) }, d * 1000);
    }, duration);
}